<?php 
class Parser 
{

  private $result = array();
  
  private $content_stream;
  
  
  private $date = null;
  private $week = array (
    "понедельник",
    "вторник",
    "среда",
    "четверг",
    "пятница",
    "суббота",
    "воскресенье"
  );
  
  private $needed_words = array (
    "пришел" => array (
      "пришел",
      "пришёл",
      "пришла", 
      "прибежал", 
      "прибежала"
    ), 
    "ушел" => array (
      "ушел",
      "ушёл",
      "ушла",
      "убежал",
      "убежала"
    ));
  
  public function getCsvWithTimes ($filename = "")
  {
    
    $this->content_stream = fopen ($filename, "rb");
    
    while(($row = fgets($this->content_stream, 4096)) !== false)
    {
      
      foreach($this->week as $day)
      {
        if(strpos($row, $day) !== false)
        {
          $this->date = trim($row);
        }
      }
      
      foreach($this->needed_words as $key => $wordlist)
      {
        if(! isset($this->result[$this->date][$key]))
        {
          $this->result[$this->date][$key] = array();
          
        }
          
        foreach($wordlist as $word)
        {
          if(strpos($row, $word) !== false)
          {
            $this->result[$this->date][$key][] = $row;
          }
        }
      }
    }

    print_r($this->result);
  }
}


?>